#!/usr/bin/env python3 

import sys
import json
import http.client
import urllib.parse

address='search-dev-01.offline.hupu.com:8200'

def call(name, paras):
    url="/actuator/metrics/{}?{}".format(name, urllib.parse.urlencode(paras))
#    print(url)
    header = {
        "Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
    }

    conn=http.client.HTTPConnection(address)
    conn.request("GET", url, None, header)
    res=conn.getresponse()
    return json.loads(res.read())

name='jvm.memory.max'
paras={
    'tag': 'area:heap'
}
res_json=call(name, paras)
print('{}: {:,}'.format(name, res_json['measurements'][0]['value']))

name='jvm.memory.committed'
paras={
    'tag': 'area:heap'
}
res_json=call(name, paras)
print('{}: {:,}'.format(name, res_json['measurements'][0]['value']))

name='jvm.memory.used'
paras={
    'tag': 'area:heap'
}
res_json=call(name, paras)
print('{}: {:,}'.format(name, res_json['measurements'][0]['value']))

name='http.server.requests'
paras={
}
res_json=call(name, paras)
print('{}: {:,}'.format(name, res_json['measurements'][0]['value']))
